package com.sharainy.contoller;

import com.alibaba.fastjson.JSONObject;
import com.sharainy.pojo.Merchant;
import com.sharainy.pojo.User;
import com.sharainy.service.MerchantService;
import com.sharainy.util.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/cancellation")
public class CancellationController {
    @Autowired
    private MerchantService merchantService;
    @RequestMapping("/pinHouseholds")
    @ResponseBody
    public RestResponse updateMerchantState(String merchantId){
        merchantService.pinHouseholds(merchantId);
        RestResponse restResponse = RestResponse.succuess();
        return restResponse;
    }
    @RequestMapping("/getSettleMerchantMsg")
    @ResponseBody
    public RestResponse getSettleMerchantMsg(HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        JSONObject jsonMain = new JSONObject();
        List<Merchant> merchantList = merchantService.selectSettleMerchant(user.getCompanyid()+"");
        jsonMain.put("merchantList",merchantList);
        RestResponse restResponse = RestResponse.succuess();
        restResponse.setData(jsonMain);
        return restResponse;

    }
}
